package com.lenovo.testreport.general.controller;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 *     基础处理器
 * </p>
 *
 * @author CJF
 * @date 2018/10
 */
@Controller
public class index {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    /**
     * 跳转到主页面
     *
     * @return 返回登陆界面url
     */
    @RequestMapping("/index")
    public String index() {
        return "/index";
    }

    /**
     * 如果未登录，跳转到主页面
     *
     * @param request 网络请求
     * @return 返回登陆界面url
     */
    @RequestMapping("/")
    public String index2(HttpServletRequest request) {
        if (redisTemplate.opsForValue().get("Lenovo-sessionId:" + request.getSession().getId()) == null) {
            return "/login";
        }
        return "/index";
    }

    /**
     * 跳转到登录页面
     *
     * @return 跳转到登录页面url
     */
    @RequestMapping("/login")
    public String login() {
        return "/login";
    }

    /**
     * 跳转到注册页面
     *
     * @return 跳转到注册页面url
     */
    @RequestMapping("/register")
    public String register() {
        return "/register";
    }

}

